package com.kt.controller;

import com.alibaba.fastjson.JSON;

import com.kt.domain.PageBean;
import com.kt.domain.Product;

import com.kt.service.imp.ProductServiceImp;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import java.io.IOException;
import java.util.List;

@WebServlet("/page.do")
public class pageServlet extends HttpServlet {
    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        res.setCharacterEncoding("utf-8");
        List<Product> list = null;
        ProductServiceImp productServiceImp = new ProductServiceImp();
        int firstPid = Integer.parseInt(req.getParameter("firstPid"));
//        String nowPage = req.getParameter("page");
        list = productServiceImp.findAllProducts(firstPid);
        if (list == null || list.isEmpty()) {
            res.getWriter().write("null");
            return;
        }
        res.getWriter().write(JSON.toJSONString(list));

    }
}
